package com.itshen.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 有返回值的线程
 */
public class CallableDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask(new MyThread());
        Thread task = new Thread(futureTask, "Task");
        task.start();

        // 获取线程返回值
        Integer result = futureTask.get();
        System.out.println("Call result: " + result);
    }
}

class MyThread implements Callable<Integer> {
    @Override
    public Integer call() throws Exception {
        System.out.println("Call Callable call method...");
        return 200;
    }
}
